var myChart = echarts.init(document.getElementById("main"));
var myChart2 = echarts.init(document.getElementById("main2"));
var way = echarts.init(document.getElementById("way"));

//藏宝统计
function treasureReport() {
    $.post('/admin/tools/treasureReport',{},function(data){
        wayOption = {
            backgroundColor: "#fff",
            tooltip: {
                trigger: 'item',
                formatter: "{b} : {c}万 ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['藏宝值汇总', '挖宝值汇总'],
                formatter: function (name) {
                    if(name == '藏宝值汇总'){
                        return name+'-'+data.totalIncome+'万';
                    }else if(name == '挖宝值汇总'){
                        return name+'-'+data.totalOut+'万';
                    }
                }
            },
            series: [
                {
                    type: 'pie',
                    radius: ['30%', '70%'],
                    center: ['50%', '50%'],
                    label: {
                        normal: {
                            formatter: '{b}:{d}%',
                        }
                    },
                    data: [
                        {value: data.totalIncome, name: '藏宝值汇总'},
                        {value: data.totalOut, name: '挖宝值汇总'}
                    ],
                }
            ]
        };
        way.setOption(wayOption);
    });
}
treasureReport();

//挖宝趋势统计
function treasureFindAnaly(type,that){
    if(that){
        $(that).parent().find('span').removeClass('back');
        $(that).addClass('back');
    }
    $.post('/admin/tools/treasureFindAnaly',{type:type},function(data) {
        option2 = {
            backgroundColor: "#fff",
            tooltip: {
                trigger: 'axis',

            },
            grid: {
                show: true,
                left: '1%',
                right: '2%',
                bottom: '4%',
                containLabel: true,
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: data.xdata
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            color: ['#2f6f95'],
            series: [
                {
                    name: '挖宝总金额',
                    type: 'line',
                    stack: '总量',
                    smooth: true,
                    lineStyle: {
                        normal: {
                            color: "#2f6f95"
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: "#96cceb"
                        }
                    },
                    data: data.ydata
                }
            ]
        };
        myChart2.setOption(option2);
    });
}
treasureFindAnaly('next');

//藏宝数据统计
function treasureAnaly(type,that){
    if(that){
        $(that).parent().find('span').removeClass('back');
        $(that).addClass('back');
    }
    $.post('/admin/tools/treasureAnaly',{type:type},function(data){
        option3 = {
            backgroundColor: "#fff",
            tooltip: {
                trigger: 'axis',

            },
            grid: {
                show: true,
                left: '1%',
                right: '2%',
                bottom: '4%',
                containLabel: true,
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: data.xdata
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            color: ['#2f6f95'],
            series: [
                {
                    name: '藏宝总金额',
                    type: 'line',
                    stack: '总量',
                    smooth: true,
                    lineStyle: {
                        normal: {
                            color: "#2f6f95"
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: "#96cceb"
                        }
                    },
                    data: data.ydata
                }
            ]
        };
        myChart.setOption(option3);
    });
}
treasureAnaly('date');


window.addEventListener("resize", function () {
  myChart.resize();
  myChart2.resize();
  way.resize();
})